package cn.italkcloud.cph.service.impl;

import cn.italkcloud.cph.entity.VosCustomerGroup;
import cn.italkcloud.cph.mapper.VosCustomerGroupMapper;
import cn.italkcloud.cph.service.IVosCustomerGroupService;
import cn.italkcloud.cph.utils.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * VOS账号组 服务实现类
 * </p>
 *
 * @author dominate
 * @since 2025-03-07
 */
@Service
public class VosCustomerGroupServiceImpl extends ServiceImpl<VosCustomerGroupMapper, VosCustomerGroup> implements IVosCustomerGroupService {

    @Override
    public boolean isOwner(int accountId, int id) {
        QueryWrapper<VosCustomerGroup> query = new QueryWrapper<>();
        query.lambda().eq(VosCustomerGroup::getAccountId, accountId).eq(VosCustomerGroup::getId, id);
        return count(query) > 0;
    }

    @Override
    public List<VosCustomerGroup> query(int accountId, String name) {
        QueryWrapper<VosCustomerGroup> query = new QueryWrapper<>();
        query.lambda().eq(VosCustomerGroup::getAccountId, accountId)
                .like(StringUtil.isNotBlank(name), VosCustomerGroup::getName, name)
                .orderByDesc(VosCustomerGroup::getSeq);
        return list(query);
    }
}
